package com.example.waibao.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    //设置允许跨域的路径
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //设置允许跨域请求的域名
                .allowedOriginPatterns("*")
//               .allowedOrigins("*")
                .allowedHeaders("*")
               .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
              //是否允许cookie
                .allowCredentials(true)
              //跨域运行时间
               .maxAge(3600);
    }
}
